#include <KIconTheme>
#include <KLocalizedContext>
#include <KLocalizedString>
#include <QApplication>
#include <QDebug>
#include <QQmlApplicationEngine>
#include <QQuickStyle>
#include "argumentspage.h"
#include "startslot.h"
#include "stopslot.h"
#include "saveslot.h"

int main(int argc, char *argv[]) {
  /*---------------初始化QML---------------*/
  KIconTheme::initTheme();
  QApplication app(argc, argv);
  KLocalizedString::setApplicationDomain("tool");
  // QApplication::setOrganizationName(QStringLiteral("KDE"));
  // QApplication::setOrganizationDomain(QStringLiteral("kde.org"));
  QApplication::setApplicationName(QStringLiteral("GUI for EIT"));
  QApplication::setDesktopFileName(QStringLiteral("org.EIT.GUI"));
  QApplication::setStyle(QStringLiteral("breeze"));
  if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
    QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
  }
  QQmlApplicationEngine engine;

  engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
  engine.loadFromModule("org.EIT.GUI", "Main");

  if (engine.rootObjects().isEmpty()) {
    return -1;
  }
  /*---------------END初始化QML---------------*/
  /*---------------初始化按钮-----------------*/
  QObject *rootObject = engine.rootObjects().first();
  QObject *swipeView = rootObject->findChild<QObject *>("pageview",Qt::FindDirectChildrenOnly);
  //连接开始成像按钮
  startSlot startfunc;
  startfunc.init(rootObject);
  QObject *button_start = swipeView->findChild<QObject *>("start");
  QObject::connect(button_start,SIGNAL(signalstart()),&startfunc,SLOT(slot_start()));
  //END连接开始成像按钮
  //连接停止按钮
  stopSlot stopfunc;
  stopfunc.init(&startfunc);
  QObject *button_stop = swipeView->findChild<QObject *>("stop");
  QObject::connect(button_stop,SIGNAL(signalstop()),&stopfunc,SLOT(slot_stop()));
  //END连接停止按钮
  //连接保存按钮
  saveSlot savefunc;
  savefunc.init(&startfunc);
  QObject *button_save = swipeView->findChild<QObject *>("save");
  QObject::connect(button_save,SIGNAL(signalsave()),&savefunc,SLOT(slot_save()));
  //END连接保存按钮
  /*--------------END初始化按钮----------------*/

  return app.exec();
}
